package com.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.entity.Goods;
import com.mall.entity.RecommendGoods;
import com.mall.mapper.RecommendGoodsMapper;
import com.mall.service.IRecommendGoodsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ShouPeng
 * @since 2024-01-15
 * 推荐商品服务实现类
 */
@Service
public class RecommendGoodsServiceImpl implements IRecommendGoodsService {
    private final String SORT = "recommend_goods_sort";

    final
    RecommendGoodsMapper recommendGoodsMapper;

    public RecommendGoodsServiceImpl(RecommendGoodsMapper recommendGoodsMapper) {
        this.recommendGoodsMapper = recommendGoodsMapper;
    }


    /**
     * 查询推荐商品
     * @param page 页码
     * @return goods
     */
    @Override
    public IPage<RecommendGoods> queryRecommendGoods(Page<RecommendGoods> page) {
        return recommendGoodsMapper.selectPage(page,new QueryWrapper<RecommendGoods>().orderByDesc(SORT));
    }

    /**
     * @return goods
     */
    @Override
    public List<Goods> queryRecommendGoods() {
        return recommendGoodsMapper.queryRecommendGoods();
    }
}
